#ifndef HISTORY_BASED_H
#define HISTORY_BASED_H

#include "HistoryManager.h"
#include "CommunicateData.h"

#include <string>
#include <string>
#include <mutex>
#include <condition_variable> // ← 添加这个

#ifdef __cplusplus
extern "C" {
#endif

#include <gio/gio.h>
#include <gio/giotypes.h>
#include <genai/text/chat.h>

#ifdef __cplusplus
}
#endif

using namespace std;

class HistoryBased
{
    
public:
    HistoryBased();
    HistoryBased(string record_path);
    ~HistoryBased();

    void init();
    void set_record_path(string path);

    string chat_with_model(string input_text);


private:
    GenAiTextSession *session;
    ChatModelConfig *config;
    ChatMessage *chatMessage;
    HistoryManager *historyManager;

    string record_path;
    int loadtimes;

    std::mutex sync_mutex;
    std::condition_variable cv;
    bool reply_ready = false;

    // 添加 callback 成员函数（而不是外部函数）
    static void chat_callback(ChatResult* result, void* user_data);
};

#endif // HISTORY_BASED_H